package com.ymttest.database.sqlwapper;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.ymt.database.SqlManager;
import com.ymttest.database.model.YmtCouponGenerateTask;
import com.ymttest.utils.EnvSetup;

public class YmtCouponGenerateTaskWapper {
	SqlManager manager;

	public YmtCouponGenerateTaskWapper() {
		manager = new SqlManager("ymt" + EnvSetup.getEnv());
	}

	public List<YmtCouponGenerateTask> selectByCouponBatchId(int couponBatchId) {
		List<YmtCouponGenerateTask> result = manager
				.getSelectResults(
						"com.ymttest.database.mapping.YmtCouponGenerateTaskMapper.selectByCouponBatchId",
						couponBatchId);
		manager.commit();
		return result;
	}
	
	public YmtCouponGenerateTask selectByPrimaryKey(int taskId) {
		YmtCouponGenerateTask result = (YmtCouponGenerateTask) manager
				.getSelectResults(
						"com.ymttest.database.mapping.YmtCouponGenerateTaskMapper.selectByPrimaryKey",
						taskId).get(0);
		manager.commit();
		return result;
	}
	

	public void setCouponBatchId(int TaskId, int CouponBatchId) {
		Map m = new HashMap();
		m.put("CouponBatchId", CouponBatchId);
		m.put("TaskId", TaskId);
		manager.update(
						"com.ymttest.database.mapping.YmtCouponGenerateTaskMapper.setCouponBatchId",
						m);
		manager.commit();
	}
	
	public List<YmtCouponGenerateTask> selectTop1() {
		List<YmtCouponGenerateTask> result = manager
				.getSelectResults(
						"com.ymttest.database.mapping.YmtCouponGenerateTaskMapper.selectTop1",
						null);
		manager.commit();
		return result;
	}
	
	public List<Map> selectMutlipySubTask()
	{
		List<Map> result = manager
				.getSelectResults(
						"com.ymttest.database.mapping.YmtCouponGenerateSubTaskMapper.selectMutlipySubTask",
						null);
		manager.commit();
		return result;
	}
	
	public int selectTop1CouponBatchIdFormSingleTask() {
		List<Map> result = manager
				.getSelectResults(
						"com.ymttest.database.mapping.YmtCouponGenerateTaskMapper.selectTop1CouponBatchIdFormSingleTask",
						null);
		manager.commit();
		return Integer.parseInt(result.get(0).get("CouponBatchId").toString());
	}
}
